<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/res/css/simple.css" />
<script type="text/javascript" src="<%=request.getContextPath() %>/res/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/res/jquery.form.js" ></script>
<title>基础数据</title>
<script>
function add(t){
	$("#edit_form_"+t)[0].reset();
	$("#id"+t).val('');
	$("#div_edit_"+t).toggle();
}
function edit(t,id){
	$("#div_edit_"+t).show();
	var url = '<%=request.getContextPath() %>/dic/load.do?id='+id;
	var callback = function(data){
		if(data.success != 1)return;
		$("#id"+t).val(data.id);
		$("#value"+t).val(data.value);
	};
	$.post(url, null,callback,'json').error(function() { alert('操作失败！'); });
}
function del(id){
	if(!confirm("确定要删除数据吗？")){
		return; 
	}
	var url = '<%=request.getContextPath() %>/dic/del.do?id='+id;
	var callback = function(data){
		if(data == "1"){
			location.reload();
 	  	}else if(data == "-1"){
 	  		alert("删除失败");
 	  	}else{
 	  		alert("系统繁忙，请稍后再试   [data:"+data+"]");
 	  	}
	};
	$.post(url, null,callback,'json').error(function() { alert('删除失败！'); });
}
function save(t){
	var queryString = $('#edit_form_'+t).formSerialize();
	var url = '<%=request.getContextPath() %>/dic/save.do';
	var callback = function(data){
		if(data == "1"){
			location.reload();
 	  	}else if(data == "-1"){
 	  		alert("保存失败");
 	  	}else{
 	  		alert("系统繁忙，请稍后再试   [data:"+data+"]");
 	  	}
	};
	$.post(url, queryString,callback,'json').error(function() { alert('操作失败！'); });
}
</script>
</head>
<body>
<jsp:include page="/admin/header.jsp" flush= "true ">
      <jsp:param name="m" value="dic"   />
</jsp:include>
<div style="margin:0 auto;width: 90%;" >
	<table cellpadding="10">
		<tr>
			<td  valign="top" >
				<div style="margin:0 auto;width: 300px;" >
				<a href="javascript:add(1);" ><span style="vertical-align:middle;"><img src="<%=request.getContextPath() %>/res/images/add2.gif"></span>添加</a> &nbsp;
				<hr />
				<div id="div_edit_1" style="display: none" >
					<form action="" method="post" id="edit_form_1" >
						<input type="hidden" id="id1" name="id" />
						<input type="hidden" id="type" name="type" value="1" />
						<table>
							<tr>
								<td align="right">名称：</td><td><input type="text" id="value1" name="value" /></td>
								<td><input type="button" value="保存" onclick="save(1);" ></td>
							</tr>
						</table>
					</form>
					<hr/>
				</div>
				<table class="myTable" >
					<tr class="chtr" >
						<td width="30" >&nbsp;</td><td width="130">客户片区</td><td width="120px" >&nbsp;</td>
					</tr>
					<c:forEach items="${customer_area_data }" var="d" varStatus="i" >
					<tr>
						<td align="center" >${d.id }</td><td>${d.value}</td>
						<td>
						&nbsp;<a href="javascript:edit(1,${d.id });" ><span style="vertical-align:middle;"><img src="<%=request.getContextPath() %>/res/images/edit.gif"></span>修改</a>&nbsp;
						&nbsp;<a href="javascript:del(${d.id });" ><span style="vertical-align:middle;"><img src="<%=request.getContextPath() %>/res/images/delete.gif"></span>删除</a>&nbsp;
						</td>
					</tr>
					</c:forEach>
				</table>
				</div>	
			</td>
			<td width="50px">&nbsp;</td>
			<td valign="top" >
				<div style="margin:0 auto;width: 300px;" >
				<a href="javascript:add(2);" ><span style="vertical-align:middle;"><img src="<%=request.getContextPath() %>/res/images/add2.gif"></span>添加</a> &nbsp;
				<hr />
				<div id="div_edit_2" style="display: none" >
					<form action="" method="post" id="edit_form_2" >
						<input type="hidden" id="id2" name="id" />
						<input type="hidden" id="type" name="type" value="2" />
						<table>
							<tr>
								<td align="right">方式：</td><td><input type="text" id="value2" name="value" /></td>
								<td><input type="button" value="保存" onclick="save(2);" ></td>
							</tr>
						</table>
					</form>
					<hr/>
				</div>
				<table class="myTable" >
					<tr class="chtr" >
						<td width="30" >&nbsp;</td><td width="130">供货商类别</td><td width="120px">&nbsp;</td>
					</tr>
					<c:forEach items="${supplier_type_data }" var="d" varStatus="i" >
					<tr>
						<td align="center" >${d.id }</td><td>${d.value}</td>
						<td>
						&nbsp;<a href="javascript:edit(2,${d.id });" ><span style="vertical-align:middle;"><img src="<%=request.getContextPath() %>/res/images/edit.gif"></span>修改</a>&nbsp;
						&nbsp;<a href="javascript:del(${d.id });" ><span style="vertical-align:middle;"><img src="<%=request.getContextPath() %>/res/images/delete.gif"></span>删除</a>&nbsp;
						</td>
					</tr>
					</c:forEach>
				</table>
				</div>
				
			</td>
		</tr>
		
	</table>
	
</div>
<%@include file="/admin/bottom.jsp" %>
</body>
</html>
